//
//  KDiscoveryTableViewCell.m
//  DrugPin
//
//  Created by guohe on 2018/9/10.
//  Copyright © 2018年 outang. All rights reserved.
//

#import "KDiscoveryTableViewCell.h"

@implementation KDiscoveryTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    [self addSubview:self.contentImageView];
    [self addSubview:self.mainTitleLabel];
    [self addSubview:self.subTitleLabel];
    [self addSubview:self.knowlegeBtn];

    [self.contentImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).mas_offset(15);
        make.left.equalTo(self).mas_offset(15);
        make.right.equalTo(self).mas_offset(-15);
        make.height.mas_equalTo(143);
    }];
    
    [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentImageView.mas_bottom).mas_offset(15);
        make.left.equalTo(self).mas_offset(15);
        make.right.equalTo(self).mas_offset(-15);
    }];
    
    [self.knowlegeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mainTitleLabel.mas_bottom).mas_offset(25);
        make.right.equalTo(self).mas_offset(-15);
        make.width.mas_equalTo(65);
        make.height.mas_equalTo(17);
    }];
    
    [self.subTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mainTitleLabel.mas_bottom).mas_offset(25);
        make.left.equalTo(self).mas_offset(15);
        make.centerY.equalTo(self.knowlegeBtn);
    }];
}

#pragma mark - getter
-(UIImageView *)contentImageView{
    if (!_contentImageView) {
        _contentImageView = [[UIImageView alloc] init];
//        NSData * dataImage = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.discoveryDataListModel.Pic]];
//        _contentImageView.image = [UIImage imageWithData:dataImage];
    }
    return _contentImageView;
}

-(UILabel *)mainTitleLabel{
    if (!_mainTitleLabel) {
        _mainTitleLabel = [[UILabel alloc] init];
//        _mainTitleLabel.text = self.discoveryDataListModel.Title;
        _mainTitleLabel.numberOfLines = 0;
        _mainTitleLabel.font = [UIFont systemFontOfSize:14];
        _mainTitleLabel.textColor = KColorOneAlpha(51,51,51);
    }
    return _mainTitleLabel;
}

-(UILabel *)subTitleLabel{
    if (!_subTitleLabel) {
        _subTitleLabel = [[UILabel alloc] init];
//        NSString *contentStr = [NSString stringWithFormat:@"%@      %@",
//                                self.discoveryDataListModel.CreateDateStr,
//                                self.discoveryDataListModel.TotalRead];
//
//        NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithString:contentStr];
//        // 创建一个文字附件对象
//        NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
//        textAttachment.image = [UIImage imageNamed:@"yuedu"];  //设置图片源
//        textAttachment.bounds = CGRectMake(0, 0, 12, 10);  //设置图片位置和大小
//        // 将文字附件转换成属性字符串
//        NSAttributedString *attachmentAttrStr = [NSAttributedString attributedStringWithAttachment:textAttachment];
//        // 将转换成属性字符串插入到目标字符串
//        [attrStr insertAttributedString:attachmentAttrStr atIndex:11];
        
//        _subTitleLabel.attributedText = attrStr;
        _subTitleLabel.numberOfLines = 0;
        _subTitleLabel.font = [UIFont systemFontOfSize:12];
        _subTitleLabel.textColor = KColorOneAlpha(153,153,153);
    }
    return _subTitleLabel;
}

-(UIButton *)knowlegeBtn{
    if (!_knowlegeBtn) {
        _knowlegeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _knowlegeBtn.layer.masksToBounds = YES;
        _knowlegeBtn.layer.cornerRadius = 4.5;
        [_knowlegeBtn setTitle:@"药理知识" forState:UIControlStateNormal];
        _knowlegeBtn.titleLabel.font = [UIFont systemFontOfSize:10];
        [_knowlegeBtn setTitleColor:KColorOneAlpha(48,138,245) forState:UIControlStateNormal];
        [_knowlegeBtn setBackgroundColor:KWhiteColor];
        _knowlegeBtn.layer.borderWidth = 1;
        _knowlegeBtn.layer.borderColor = KColor(48,138,245, 1).CGColor;
    }
    return _knowlegeBtn;
}

@end
